package com.zdzx.controller.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdzx.common.result.PageInfo;
import com.zdzx.common.result.PageUtil;
import com.zdzx.common.result.Result;
import com.zdzx.common.result.ResultCode;
import com.zdzx.common.result.ResultUtil;
import com.zdzx.mapper.BannerMapper;
import com.zdzx.model.service.content.vo.Banner;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "webbanner")
@RestController()
@RequestMapping("/web")
public class WebBannerController {
	
	
	@Autowired
	private BannerMapper bannerMapper;
	
	@ApiOperation(value = "获取列表", notes = "")
	@GetMapping("/banner")
	public Result<PageInfo<Banner>> list(@ApiParam("") @RequestParam(value = "pageNum", required = false) Integer pageNum,
			@ApiParam("") @RequestParam(value = "pageSize", required = false) Integer pageSize){
		if(pageNum==null||pageSize==null) {
			pageNum=1;
			pageSize=10;
		}
		Page<Banner> page = new Page<>(pageNum==null?1:pageNum, pageSize==null?10:pageSize);
		QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByAsc("sort");
		IPage<Banner> info = bannerMapper.selectPage(page, queryWrapper);
		PageInfo<Banner> data = PageUtil.data(info.getPages(),info.getCurrent(),info.getTotal(),info.getRecords());
		return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), null, data);
	}
}
